package com.gy.bearhelps.home.adapter;


import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.gy.bearhelps.R;
import com.gy.bearhelps.util.ListViewItemListener;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

/** ��ҳviewpager adapter*/
public class HomePagerAdAdapter extends PagerAdapter {

	private Context context;
	private ArrayList<String> list;
	public ListViewItemListener listener;

	public HomePagerAdAdapter(Context context, ArrayList<String> list) {
		this.context = context;
		this.list = list;
	}

	public void setListener(ListViewItemListener listener){
		this.listener = listener;
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0 == arg1;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
//		return list.size();
		return Integer.MAX_VALUE;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		/*
		 * if (list.size() > 0) { if(null != mViewList.get(position))
		 * container.removeView(mViewList.get(position)); }
		 */
	}

	@Override
	public int getItemPosition(Object object) {
		return super.getItemPosition(object);
	}

	@Override
	public Object instantiateItem(ViewGroup container, final int position) {
		View view = View.inflate(context, R.layout.activity_main_ad_item, null);
		ImageView imageView = (ImageView) view.findViewById(R.id.ad_image);
		ImageLoader.getInstance().displayImage(list.get(position % list.size()),imageView);
		container.addView(view, 0);
		imageView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if(listener != null){
					listener.doPassActionListener(null,0,position % list.size(),"");
				}
			}
		});
		return view;
	}

}
